Removable Media in Advanced Ladder

See also: Project Toolbox for Advanced Ladder

 

Topic Menu

 

Removable Media Topics include:

Using Removable Media Functions in Cscape, Part 1

Using Removable Media Functions in Cscape, Part 2

The Removable Media function blocks are used to read or write files in to the microSD or USB. Comma-separated value files can be read from or written to the Removable Media card making it possible to datalog or otherwise store and retrieve enormous amounts of data. These files can be read or created using a spreadsheet program for data processing. The ability to Copy, Delete and Rename files, is also available. All OCS models provide a slot for a CompactFlash memory card.

Functions of RM blocks

  1. Write RM csv: This function allows writing of a comma-separated value file to the CompactFlash interface from the controller register space. The file format of the value file uses commas to separate values.

  2. Read RM csv: This function allows reading of a comma-separated value file from the CompactFlash interface into the controller register space. The file format of the value file uses commas to separate values.

  3. Rename RM csv: This function allows renaming a file on the CompactFlash card. The data in the file is not changed during this function.

  4. Delete RM csv: This function allows deleting a file on the CompactFlash card.

  5. Copy RM csv: This function allows copying a file on the CompactFlash card

Filenames

The OCS Removable Media function blocks support the flash with a DOS/Windows standard fat-16 file system. All names must be limited to the "eight dot three" format where the filename contains eight characters a period then a three-character extension. The entire filename including any path must be less than or equal to 147 characters.

When creating filenames and directories it is sometimes desirable to include parts of the current date or time. There are six special symbols that can be entered into a filename that are replaced by the OCS with current time and date information.

 Symbol

Description

Example

$Y

Substitutes the current 2-digit year

2021 = 21

$M

Substitutes the current month with a 2-digit code

March = 03

$D

Substitues the current 2-digit day

22nd = 22

$h

Substitutes the current 2-digit hour in 24-hour format

4pm = 16

$m

Substitutes the current 2-digit minute

$s

Substitutes the current 2-digit second

$p

Substitutes the currently displayed 4-digit screen number (1-1023)

(Intended mainly for screen capture)

Screen 53 = 0053

The following are examples of the substituted time/date filenames:

Current date and time: March 1, 2004 3:45:34 PM

Filename: Data$M$D.csv = Data0301.csv

Filename: Year$Y\Month$M\aa$D_$h.csv = Year04\Month03\aa01_15.csv

Filename: Month_$M\Day_$D\$h_$m_$s.csv = Month_03\Day_01\15_45_34.csv

Note:  

  1. The user MUST specify the filename extension like .csv, .pgm, .bmp or .jpeg. It is not automatically added.

  2. All the symbols start with the dollar sign ($) character. Date symbols are in upper case, time symbols are in lower case.

  3. In order to use the above six special symbols in IEC, user must configure an extra $ sign ($ is the escape character used by compiler in IEC to allow user to enter an hexadecimalClosed A base-16 numbering system which uses the symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F for numeral. code directly in the string) as shown in example below:

Current date and time:March 1, 2004 3:45:34PM

Filename: Data$$M$$D.csv = Data0301.csv

Filename: Year$$Y\Month$$M\aa$$D_$$h.csv = Year04\Month03\aa01_15.csv

Filename: Month_$$M\Day_$$D\$$h_$$m_$$s.csv = Month_03\Day_01\15_45_34.csv

Return to the Top: Removable Media in Advanced Ladder

USB and RM Functions

In firmware version 12.60 onwards, all RM Function blocks (Read, Write, Rename, Delete and Copy), in models that have USB type A connectors, support USB Flash drives up to 2 GB in size, if they are formatted with the FAT16 file system. (When using a PC to format a USB Flash drive, the type of file system to select is typically FAT.)

In a ladder function block, the USB Flash drive can be specified by prefixing a filename with the 2-character string B: If the prefix is omitted, or if it is A:, the main media card (Compact Flash or MicroSD) is specified.

Example: To copy all .csv files from the main media card’s group1 folder to a USB drive’s save1 folder, the source filename string should be \group1\*.csv or A:\group1\*.csv and the destination filename string should be B:\save1.

Note: The drive prefix is not case-sensitive, so B: and b: are equivalent.

Return to the Top: Removable Media in Advanced Ladder

Status Values with RM Blocks

Status Values returned by RM function Blocks:

Value

Description

0

Operation completed successfully

-1

End of file was reached before completing

-2

Function is active, waiting for operation to complete

-3

Function is waiting on another CF function to complete

-4

Function block is inactive (usually no power flow)

1

Card present but unknown format

2

No card in slot

3

Card present, but not supported

4

Card swapped before operation was complete

5

Unknown error

66

File / Path specified does not exist

73

Bad file descriptor (corrupt file)

77

Attempt to open / rename file that is open

81

Specified file already exist

86

Function block contains illegal parameter

88

Too many open files*

92

Attempt to write failed

94

Sharing violation*

95

No disk present*

96

Directory structure corrupt

98

Incorrect data format

1000

List Bad Path (check for path, "\" must be used)

1001

List Path too long

1002

List Empty

1003

List Permission

1004

List wait update

* These Status Codes never should occur, being duplicates of higher priority status codes.

Return to the Top: Removable Media in Advanced Ladder

System Registers with RM Blocks

System registers used with Removable Media

%SR175 Status - This shows the current status of the Removable Media interface.

Possible status values:

0

Removable Media Interface OK

1

Card Present but unknown format

2

No card in slot

3

Card present, but not supported

4

Card swapped before operation was complete

5

Unknown error

6

Access protected

%SR176 Free Space - This 32-bit register shows the free space on the Removable Media card in bytes.

%SR178 Card Capacity - This 32-bit register shows the total card capacity in bytes.